<?

/********************************************
* event.php
*
* This page displays the relevent information about an event.
*
********************************************/

//include files
include "config.php";
include "../lib/db.php";
include "../lib/tbatv_lib.php";

$tba = new tbatvController();

//get passed arguments
$eventid = sanatizeGet($_GET['eventid']);
if ($eventid == "") {
	$eventid = sanatizeGet($_GET['event']);
} 
if ($eventid == "") {
    $eventid = 0;
}
//look up what event we're dealing with
$eventid = stripslashes($eventid);
$event = new Event($eventid);

$mode = $_GET["mode"];
if ($mode == "" OR $mode == Null) {
	if ($event->hasMatches()) {
		$mode = "match_results";
	} else {
		$mode = "teams";
	}
}

//include the header, which uses the matchinfo.
$title = "{$event->getName()} ({$event->getYear()})";
$haslightbox = 1;
include "header.php";

//Echo the event information
?>
<h1><? echo $event->linkto() ?></h1>

<table class="table_alt">
	<tr class="table_toprow"><td colspan="2">Event Information: <? echo $event->getName()?> (<? echo $event->getYear() ?>)</td></tr>
	<tr class="table_row0"><td><strong>Week:</strong></td><td><? echo $tba->stringWeek($event->getWeek()) ?></td></tr>
	<tr class="table_row1"><td><strong>Event Location:</strong></td><td><? echo $event->getLocation()?></td></tr>
	<tr class="table_row0"><td><strong>Teams Attending:</strong></td><td><? echo $event->getTeamCount() ?></td></tr>
</table>
<br />
<table id="more_info_links">
	<tr><td class="attendees_link block_link"><a href="<? echo $BASE_PATH . "event/" . $event->getCodeString() . "/teams"?>"/>Click here to view<br /> teams attending</a></td>
	<td class="matchresults_link block_link"><a href="<? echo $BASE_PATH . "event/" . $event->getCodeString() . "/match_results"?>">Click here for <br /> match listings</a></td></tr>
</table>

<? 

if ($mode == "teams") {
	
	?><h2>Teams Attending the <?echo $event->getName() ?></h2>
	<p>Below is a list of teams attending the <?echo $event->getYear() . " " . $event->getName() ?>. For each team, you can click the <strong>camera icon (<img src="<? echo $BASE_PATH ?>/images/camera_icon.png" />) for a picture</strong> or the <strong>team name for video of their matches this year</strong> and more information about the team. This list may not be final.</p></p>	<?
	
	$list_of_teams = $event->getAllTeams();
	include "views/event_list_of_teams.php";
}

if ($mode == "match_results") {
	//iterate through levels of play and output matches for each one. This looping iterative method is a huge improvement
	//over the old "grab all at once" method.
	
	?>
    <h2>Match Listing</h2>
	<? 
	if ($event->hasMatches()) {
	    $list_of_matches = $event->getAllMatches();
	    include "views/list_of_matches.php";
	} else {
	    print "<p>No matches have been played at " . $event->getName() . " yet.</p>";
	}

	if ($event->hasEliminations()) {
		echo "<br />";
		generateElimsBracket($event->getEventID());
	}

}

include "footer.php";
?>


